package 枚举与尺聚法;

import java.util.LinkedList;

public class 组合 {
    public static void main(String[] args) {
        int n = 4;
        int k = 2;
        dfs2(n, k, 1, new LinkedList<Integer>());

    }

    private static void dfs2(int n, int k, int start, LinkedList<Integer> stack) {
        if (stack.size() == k) {
            System.out.println(stack);
            return;
        }
        for (int i = start; i <= n; i++) {
            stack.push(i);
            dfs2(n, k, start + 1, stack);
            stack.pop();
        }
    }
}
